#include "stdafx.h"
#include "Count.h"
#include <iostream>
using namespace std;

Count::Count(const int & size)
{
	this->minDistance = -1;
	if (size > 50)
	{
		this->size = 50;
	}
	else
	{
		this->size = size;
	}
	init();


}

Count::~Count()
{
	delete[]p;
}

void Count::doCount()
{
	for (int i = 0; i < this->size - 1; i++)
	{
		for (int j = i + 1; j < this->size; j++)
		{
			double a = (p[i].x - p[j].x)*(p[i].x - p[j].x);
			double b = (p[i].y - p[j].y)*(p[i].y - p[j].y);
			if (minDistance < 0)
			{
				minDistance = a + b;
			}
			else
			{
				if (a + b < minDistance)
				{
					minDistance = a + b;
					this->point1 = i;
					this->point2 = j;
				}
				//a + b < minDistance;

			}

		}
	}
	cout << endl << endl;
	cout << "point1=" << this->point1 << "  point2=" << this->point2 << endl;
	cout << "min=" << sqrt(this->minDistance) << endl;
}

void Count::init()
{
	this->p = new Point[size];
	srand(time(nullptr));
	for (int i = 0; i < this->size; i++)
	{
		//int rNumber = rand() % 100;
		p[i].x = rand() % 100;
		p[i].y = rand() % 100;
		cout << i << "  " << p[i].x << "  " << p[i].y << endl;

	}
}
